package com.ml.mall.api.remark;

import com.ml.mall.annotation.LogMethodInvokeInformation;
import com.ml.mall.bean.base.ApiRestResult;
import com.ml.mall.bean.req.remark.RemarkNewDto;
import com.ml.mall.bean.req.remark.RemarkQueryAllDto;
import com.ml.mall.entity.remark.SysRemark;
import com.ml.mall.enums.CommonEnum;
import com.ml.mall.exception.BizException;
import com.ml.mall.service.remark.SysRemarkService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.List;

/**
 * @description description
 * @author yx
 * @date 2021/10/15
 * @version 1.0
*/
@Api(tags = "【auth】通用备注接口")
@RestController
@RequestMapping("/remark")
public class SysRemarkController {
    @Autowired
    private SysRemarkService sysRemarkService;

    @ApiOperation("添加备注")
    @PostMapping("/new")
    @LogMethodInvokeInformation("添加备注")
    public ApiRestResult remarkNew(@RequestBody @Valid RemarkNewDto dto){
        boolean result = sysRemarkService.save(dto);
        if(!result){
            throw new BizException(CommonEnum.INSERT_ERROR);
        }
        return ApiRestResult.ok(true);
    }

    @ApiOperation("查询备注")
    @PostMapping("/query_all")
    @LogMethodInvokeInformation("查询备注")
    public ApiRestResult remarkQueryAll(@RequestBody @Valid RemarkQueryAllDto dto){
        List<SysRemark> result = sysRemarkService.queryAll(dto);
        if(null == result){
            throw new BizException(CommonEnum.SELECT_ERROR);
        }
        return ApiRestResult.ok(result);
    }
}
